﻿@model ABCTile.ViewModel.EstimateProposalIndexData

@{
    ViewBag.Title = "Proposal";
}

<h2>Proposal</h2>
<p>The Proposal Date is @DateTime.Now</p>

<table>
    <tr>
        <th></th>
        <th>
            Project Id
        </th>
        <th>
            Estimate Total
        </th>
        <th>
            Estimate Date
        </th>
        <th>
            Estimate Comment
        </th>
        <th>
            Estimate Status
        </th>
        
    </tr>

    @foreach (var item in Model.Estimates)
    {
        
        string selectedRow = "";
        if (item.Id == ViewBag.EstimateID)

        {
            selectedRow = "selectedrow";
        }

        <tr class="@selectedRow" valign="top">  
            <td>  
                @Html.ActionLink("Finalize", "Index", "Proposal", new { id = item.Id }, null)
            </td>  
            <td>  
                @item.ProjectId  
            </td>  
            <td>  
                $@String.Format("{0:0.00}", item.EstimateTotal)
            </td>  
            <td>  
                @item.EstimateDate 
            </td>  
            <td>  
                @item.EstimateComment 
            </td>  
            <td>  
                @item.EstimateStatus 
            </td>  
        </tr>  
    }

</table>

@if (Model.Proposals != null)
{
    if (ViewBag.proposalcount == 0)
    {
        <p>
            @Html.ActionLink("Create New", "Create")
        </p>
    }
    <p></p>
<table>
    <tr>        
        <th>
            Insurance
        </th>
        <th>
            Profit
        </th>
        <th>
            Benifits
        </th>
        <th>
            Federal Tax
        </th>
        <th>
            State Tax
        </th>
        <th>
            Social-Security
        </th>
        <th>
            Master Cost
        </th>
        <th>
            Assistant Cost
        </th>
        <th>
            Tool Rental
        </th>
         <th>
            Proposal Status
        </th>

        <th></th>
    </tr>

    
@{
    decimal ZTotal = 0;
    decimal Insurance = 0;
    decimal Profit = 0;
    decimal Benifits = 0;
    decimal FedTax = 0;
    decimal StateTax = 0;
    decimal SocialSecurity = 0;
    decimal Labor = 0;
    decimal ToolRental = 0;
}

@foreach (var item in Model.Proposals)
{

    string selectedRow = "";
    if (item.Id == ViewBag.EstimateID)
    {
        selectedRow = "selectedrow";
    }


    var AdditionalCost = (@ViewBag.zoutotal * item.InsurancePercentage) / 100 + (@ViewBag.zoutotal * item.ProfitPercentage) / 100 + (@ViewBag.zoutotal * item.Benifits) / 100
                      + (@ViewBag.zoutotal * item.FederalTax) / 100 + (@ViewBag.zoutotal * item.StateTax) / 100 + (@ViewBag.zoutotal * item.SocialSecurity) / 100
                      + (item.MasterHourCost) + (item.AssistantHourCost) + (item.ToolRentalCost);
    var GrandTotal = @ViewBag.zoutotal + AdditionalCost;

    Insurance = (@ViewBag.zoutotal * item.InsurancePercentage) / 100;
    Profit = (@ViewBag.zoutotal * item.ProfitPercentage) / 100;
    Benifits = (@ViewBag.zoutotal * item.Benifits) / 100;
    FedTax = (@ViewBag.zoutotal * item.FederalTax) / 100;
    StateTax = (@ViewBag.zoutotal * item.StateTax) / 100;
    SocialSecurity = (@ViewBag.zoutotal * item.SocialSecurity) / 100;
    Labor = (item.MasterHourCost) + (item.AssistantHourCost);
    ToolRental = (item.ToolRentalCost);
    ZTotal = ZTotal + GrandTotal;
    <tr class="@selectedRow" valign="top">

      
        <td>
            %@Html.DisplayFor(modelItem => item.InsurancePercentage)             
        </td>
        <td>
            %@Html.DisplayFor(modelItem => item.ProfitPercentage)
        </td>
        <td>
            %@Html.DisplayFor(modelItem => item.Benifits)
        </td>
        <td>
            %@Html.DisplayFor(modelItem => item.FederalTax)
        </td>
        <td>
            %@Html.DisplayFor(modelItem => item.StateTax)
        </td>
        <td>
            %@Html.DisplayFor(modelItem => item.SocialSecurity)
        </td>
        <td>
            $@Html.DisplayFor(modelItem => item.MasterHourCost)
        </td>
        <td>
            $@Html.DisplayFor(modelItem => item.AssistantHourCost)
        </td>
        <td>
            $@Html.DisplayFor(modelItem => item.ToolRentalCost)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.ProposalStatus)
        </td>
         <td>
            @Html.ActionLink("Edit", "Edit", new { id = item.Id }) |
            @Html.ActionLink("Details", "Details", new { id = item.Id }) |
            @Html.ActionLink("Delete", "Delete", new { id = item.Id })
        </td>
    </tr>
}
</table>
 


if (ViewBag.proposalcount != 0)
{
        
<table>
    <tr>
        <td> 
            Estimate Total  
        </td>
        <td style="text-align: right;">
            $@String.Format("{0:0.00}", @ViewBag.zoutotal) 
        </td>
    </tr>
    <tr>
        <td> 
            Insurance Amount  
        </td>
        <td style="text-align: right;">
            $@String.Format("{0:0.00}", Insurance) 
        </td>
    </tr>
    <tr>
        <td> 
            Profit Amount 
        </td>
        <td style="text-align: right;">             
            $@String.Format("{0:0.00}", @Profit)
        </td>
    </tr>
    <tr>
        <td> 
            Benifits Amount  
        </td>
        <td style="text-align: right;">         
            $@String.Format("{0:0.00}", @Benifits)
        </td>
    </tr>
    <tr>
        <td> 
            Federal Tax  
        </td>
        <td style="text-align: right;">   
            $@String.Format("{0:0.00}", @FedTax)
        </td>
    </tr>
    <tr>
        <td> 
            State Tax  
        </td>
        <td style="text-align: right;">   
            $@String.Format("{0:0.00}", @StateTax)
        </td>
    </tr>
    <tr>
        <td> 
            Social Security  
        </td>
        <td style="text-align: right;">   
            $@String.Format("{0:0.00}", @SocialSecurity)
        </td>
    </tr>
    <tr>
        <td> 
            Labor  
        </td>
        <td style="text-align: right;">   
            $@String.Format("{0:0.00}", @Labor)
        </td>
    </tr>
    <tr>
        <td> 
            Tool Rental  
        </td>
        <td style="text-align: right;">   
            $@String.Format("{0:0.00}", @ToolRental)
        </td>
    </tr>
    <tr>
        <td> 
            <h3>The Proposal Grand Total is:</h3>   
        </td>
        <td style="text-align: right;"> 
            <h3>$@String.Format("{0:0.00}", @ZTotal)</h3>
        </td>
    </tr>

</table>  
}

}
    
